using System;
using System.Collections;
using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class EnumerableDuplicateRuleAttributeTest
    {


        [Test]
        public void CheckValues()
        {
            var ruleAttribute = new EnumerableDuplicateRuleAttribute();

            const string expectedEqualityComparerTypeName = "System.StringComparer";
            ruleAttribute.EqualityComparerTypeName = expectedEqualityComparerTypeName;
            const string expectedEqualityComparerPropertyName = "InvariantCulture";
            ruleAttribute.EqualityComparerPropertyName = expectedEqualityComparerPropertyName;
            Assert.AreEqual(expectedEqualityComparerTypeName, ruleAttribute.EqualityComparerTypeName);
            Assert.AreEqual(expectedEqualityComparerPropertyName, ruleAttribute.EqualityComparerPropertyName);

            var propertyRule = (EnumerableDuplicateRule)ruleAttribute.CreateInstance(new MockPropertyDescriptor<IList>("foo"));
            var parameterRule = (EnumerableDuplicateRule)ruleAttribute.CreateInstance(new MockParameterDescriptor<IList>("foo"));
            var fieldRule = (EnumerableDuplicateRule)ruleAttribute.CreateInstance(new MockFieldDescriptor<IList>("foo"));

            Assert.AreEqual(StringComparer.InvariantCulture, propertyRule.Comparer);
            Assert.AreEqual(StringComparer.InvariantCulture, parameterRule.Comparer);
			Assert.AreEqual(StringComparer.InvariantCulture, fieldRule.Comparer);

        }


        [Test]
        public void CallAttributeTester()
        {
            AttributeTester.CheckDefaultValues<IList>(new EnumerableDuplicateRuleAttribute(), true, true, true);
            AttributeTester.CheckNonDefaultValues<IList>(new EnumerableDuplicateRuleAttribute(), true, true, true);
        }

    }
}